<template>
  <div class="dialog">
    <el-dialog :title="'诊断项' + titleText" :visible.sync="showDialog" width="40%" top="0" :close-on-click-modal="false"
      @close="cancel">
      <el-form ref="ruleForm" label-position="left" :model="formData" :rules="rules" class="el-form">
        <el-form-item label="诊断项名称	" class="w50p" prop="diagnosisItemName">
          <el-input v-model="formData.diagnosisItemName" clearable placeholder="" />
        </el-form-item>
        <el-form-item label="关联品种" class="w50p" prop="fishVarietyId">
          <el-select filterable clearable v-model="formData.fishVarietyId" filterable clearable>
            <el-option v-for="item of FishVarietyList" :key="item.fishVarietyId" :label="item.varietyName"
              :value="item.fishVarietyId" />
          </el-select>
        </el-form-item>

        <el-form-item label="主要判断特征" class="w50p" prop="mainFeaturesFlag">
          <el-select filterable clearable v-model="formData.mainFeaturesFlag" clearable>
            <el-option label="是" :value="true" />
            <el-option label="否" :value="false" />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button class="cancelbtn" @click="cancel()">取 消</el-button>
        <el-button type="primary" class="savebtn" @click="save('ruleForm')">保 存</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import FishVarietyApi from "@/api/basic-info-manage/fishVariety/index";
import FeaturesTypeManageApi from "@/api/disease-bank-manage/features-type-manage/index";

export default {
  name: "",
  components: {},
  props: {
    // 弹框名称
    titleText: {
      type: String,
      default: ""
    },
    nowChanceStau: {
      type: String,
      default: ""
    },
    show: {
      type: Boolean,
      default: false
    },
    editObject: {
      type: [Object],
      default: () => {
        return {};
      }
    }
  },
  data () {
    let checkInt = (rule, value, callback) => {
      if (value) {
        if (Number(value) && value % 1 === 0) {
          callback();
        } else {
          return callback(new Error("请输入整数！"));
        }
      }
    };
    return {
      formData: {},
      FishVarietyList: [],
      diagnosisItemList: [],
      // diagnosisItemSymbolList:[],
      rules: {
        diagnosisItemName: [
          {
            required: true,
            message: "请输入",
            trigger: ["change", "blur"]
          }
        ],
        fishVarietyId: [
          {
            required: true,
            message: "请选择",
            trigger: ["change", "blur"]
          }
        ],
        mainFeaturesFlag: [
          {
            required: true,
            message: "请选择",
            trigger: ["change", "blur"]
          }
        ]
      },
      showDialog: this.show
    };
  },
  computed: {},
  watch: {
    show (v) {
      this.showDialog = v;
      this.$refs.ruleForm && this.$refs.ruleForm.resetFields()
    },
    nowChanceStau (v) {
      if (v === "add") {
        this.formData = {
          staffName: sessionStorage.getItem("staffName")
        };
      }
      if (v === "edit") {
        this.formData = this.editObject;
      }
      this.$refs.ruleForm && this.$refs.ruleForm.resetFields()
    }
  },
  created () { },
  mounted () {
    this.qureyFishVariety();
    // this.qureyDiagnosisItem()
  },
  methods: {
    qureyFishVariety () {
      FishVarietyApi.queryByCondition().then(res => {
        this.FishVarietyList = res.data;
      });
    },

    // 请求数据
    // async qureyDiagnosisItem(){
    //   const res =await FiseaseFeaturesManageApi.queryByCondition({})
    //   this.diagnosisItemSymbolList=res.data
    // },
    save (formData) {
      this.$refs[formData].validate(valid => {
        if (valid) {
          if (this.nowChanceStau === "edit") {
            FeaturesTypeManageApi.edit(this.formData).then(res => {
              if (res.success === true) {
                this.$message.success("添加成功！");
                this.close();
              } else {
                this.$message.error(res.message);
              }
            });
          } else if (this.nowChanceStau === "add") {
            FeaturesTypeManageApi.add(this.formData).then(res => {
              if (res.success === true) {
                this.$message.success("添加成功！");
                this.close();
              } else {
                this.$message.error(res.message);
              }
            });
          }
        } else {
          return false;
        }
      });
    },
    close () {
      this.$emit("closeDialog");
    },
    cancel () {
      this.$emit("cancelDialog");
    }
  }
};
</script>

<style lang="scss" scoped></style>
